package com.songshu.sca.nacosConfig;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 *
 * 使用前缀方式读取nacos中的第二个配置。
 * 配置文件中有相同的配置项会加载最新的。
 */
@Slf4j
@Configuration
@ConfigurationProperties(prefix = "myuser")
public class NacosConfig1Test {

    private String name;

    private String age;

    private String address;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @Override
    public String toString() {
        return "NacosConfigTestUser{" +
                "myuser_name='" + name + '\'' +
                ", myuser_age='" + age + '\'' +
                ", myuser_address='" + address + '\'' +
                '}';
    }

    @PostConstruct
    public void printConfig(){
        log.info("config1读取nacos配置文件内容如下： {}, {}, {}", name, age, address);
    }

}
